package com.leozhang.app;

public class Test {

    private static long parseStoreSize(String storeSize) {
        double multiplier = 1.0; // 默认不乘以任何倍数
        if (storeSize.endsWith("kb")) {
            multiplier = 1024.0;
        } else if (storeSize.endsWith("mb")) {
            multiplier = 1024.0 * 1024.0;
        } else if (storeSize.endsWith("gb")) {
            multiplier = 1024.0 * 1024.0 * 1024.0;
        }
        System.out.println("multiplier: " + multiplier);

        // 移除字母后解析大小
        System.out.println("storeSize: " + storeSize);
        storeSize = storeSize.replaceAll("[a-zA-Z]", "");
        System.out.println("storeSize: " + storeSize);
        try {
            double size = Double.parseDouble(storeSize);
            return (long) (size * multiplier);
        } catch (NumberFormatException e) {
            return -1; // 解析失败返回-1或者其他错误处理
        }
    }

    public static void main(String[] args) {
        String[] lines = {
                "filebeat-6.8.0-2025.01.16 16.9gb",
                "filebeat-6.8.0-2025.01.17 19.5gb"
        };
        Long totalStoreSize = 0l;

        if (lines.length > 0) {
            for (String line : lines) {
                String[] parts = line.split(" ");
                long storeSizeBytes = parseStoreSize(parts[1]);
                totalStoreSize += storeSizeBytes;
            }
        }

        System.out.println("totalStoreSize: " + totalStoreSize);

    }
}
